// 引入Vue
import Vue from 'vue';

// const def = require('@/assets/images/loading.gif');

// 限制input框只允许输入正整数
const enterNumber = Vue.directive('enterNumber', {
  inserted: function(el) {
    el.addEventListener('keypress', function(e) {
      e = e || window.event;
      let charcode = typeof e.key === 'number' ? e.key : e.code;
      let re = /\d/;
      if (!re.test(String.fromCharCode(charcode)) && charcode > 9 && !e.ctrlKey) {
        if (e.preventDefault) {
          e.preventDefault();
        } else {
          e.returnValue = false;
        }
      }
    });
  }
});

export default enterNumber;